//
//  _iOSUtils_Geometry.m
//  iOSUtils
//
//  Created by HJC on 11-9-8.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "_iOSUtils_SmallFuns.h"


extern CGFloat* ArrayFindCGFloat(CGFloat* begin, CGFloat* end, CGFloat val)
{
    for (CGFloat* ptr = begin; ptr != end; ptr++)
    {
        if (*ptr == val)    
        {
            return ptr;
        }
    }
    return 0;
}


extern NSInteger* ArrayFindNSInteger(NSInteger* begin, NSInteger* end, NSInteger val)
{
    for (NSInteger* ptr = begin; ptr != end; ptr++)
    {
        if (*ptr == val)    
        {
            return ptr;
        }
    }
    return 0;
}


extern CGRect CGRectBoundsOfPoints(CGPoint* points, NSInteger count)
{
    CGPoint minPt = points[0];
    CGPoint maxPt = points[0];
    
    for (NSInteger idx = 1; idx < count; idx++)
    {
        CGPoint pt = points[idx];
        minPt.x = MIN(minPt.x, pt.x);
        minPt.y = MIN(minPt.y, pt.y);
        maxPt.x = MAX(maxPt.x, pt.x);
        maxPt.y = MAX(maxPt.y, pt.y);
    }
    
    CGRect rect;
    rect.origin = minPt;
    rect.size = CGPointMinusPoint(maxPt, minPt);
    
    return rect;
}
